package com.luofan.controller;


import com.luofan.common.result.Result;
import com.luofan.common.result.ResultCodeEnum;
import com.luofan.entity.po.Section;
import com.luofan.entity.vo.SectionMemberVO;
import com.luofan.entity.vo.SectionVO;
import com.luofan.service.SectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 教研室表 前端控制器
 * </p>
 *
 * @author
 * @since 2025-03-26
 */
@RestController
@RequestMapping("/section")
public class SectionController {

    @Autowired
    private SectionService sectionService;

    //获取所有教研室信息列表
    @GetMapping
    public Result<List<SectionVO>> listAllSection() {
        List<SectionVO> sectionList = sectionService.listAllSection();
        return Result.ok(sectionList);
    }

    //根据用户id获取用户所在的教研室的信息
    @GetMapping("/{id}")
    public Result<Section> getSectionByUserId(@PathVariable Long id) {
        Section section = sectionService.getSectionByUserId(id);
        return Result.ok(section);
    }

    //根据教研室id获取所属的成员信息(主任单独列出来)
    @GetMapping("/member/{id}")
    public Result<SectionMemberVO> listMember(@PathVariable Long id) {
        SectionMemberVO sectionMemberVO = sectionService.listMember(id);
        return Result.ok(sectionMemberVO);
    }

    //管理员 新增教研室
    @PostMapping
    public Result<String> saveSection(@RequestBody Section section) {
        ResultCodeEnum resultCodeEnum = sectionService.saveSection(section.getName());
        return Result.build(null, resultCodeEnum);
    }

    //管理员 修改教研室名称
    @PutMapping
    public Result<String> updateSection(@RequestBody Section section) {
        ResultCodeEnum resultCodeEnum = sectionService.updateSection(section);
        return Result.build(null, resultCodeEnum);
    }

}
